﻿/**
 * Created in 2012-2-24.
 */
package kit4j.tests.jdk.basic;

import static org.junit.Assert.assertTrue;

import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

/**
 * 
 * @author MiniKnife
 *
 */
public class InstanceofTest {
	
	private int[] intArray;
	private byte[] byteArray;
	private char[] charArray;
	private Object[] objectArray;
	private List<String> stringList;
	
	@Before
	public void setUp() {
		intArray = new int[10];
		byteArray = new byte[10];
		charArray = new char[10];
		objectArray = new Object[10];
		stringList = new ArrayList<String>();
	}
	
	@After
	public void tearDown() {
		intArray = null;
		byteArray = null;
		charArray = null;
		objectArray = null;
		stringList = null;
	}
	
	@Test
	public void testIntArrayInstanceof(){
		assertTrue(intArray instanceof int[]);
		assertTrue(Integer.TYPE.equals(intArray.getClass().getComponentType()));
	}
	
	@Test
	public void testByteArrayInstanceof(){
		assertTrue(byteArray instanceof byte[]);
	}
	
	@Test
	public void testCharArrayInstanceof(){
		assertTrue(charArray instanceof char[]);
	}
	
	@Test
	public void testObjectArrayInstanceof(){
		assertTrue(objectArray instanceof Object[]);
	}
	
	@Test
	public void testListInstanceof(){
		assertTrue(stringList instanceof List<?>);
	}
	
	@Ignore
	@Test
	public void testGenericSuperclass() {
		System.out.println(stringList.getClass().getGenericSuperclass());
		System.out.println(stringList.getClass().getSuperclass());
	}
	
	@Test
	public void testGetTypeParameters() {
		for(TypeVariable<?> type : stringList.getClass().getTypeParameters()) {
			System.out.println(type.getGenericDeclaration());
		}
	}

}
